//define(['js/module.js','jquery'],function(controllers,$){
    'use strict';
	angular.module('backcenter.billSettingSingle', [])
    .controller('billSettingSingleCtrl'
			,[ '$rootScope', '$scope', '$state', 'BizData'
			   , '$uibModalInstance','params', 'title'
                                       ,f])
	function f($rootScope, $scope, $state, BizData
					   , $uibModalInstance, params, title
					   ) {


		var Model = this;
		
		Model.dataBillSettingAfterRefresh = function(event) {
			//打开窗口之后，至于编辑状态
			Model.edit();
		}

		/**
		name:bizData#onBeforeDelete
		description: <b>[回调型事件]</b>业务数据删除前
		@param {object} event 它的结构如下:<br/>
		{
			"source":组件的js对象
			,"cancel":可修改	，设置为true后中断当前delete动作
			,"deleteIDList":删除的行Id数组
		}
		*/
		Model.dataBillSettingBeforeDelete = function(event) {
//			alert(event.deleteIDList[0]);
		}
		/**
		name:bizData#onAfterDelete
		description: <b>[回调型事件]</b>业务数据删除后
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"deleteIDList" : 删除的行Id数组
		}
		</xmp>	
		*/
		Model.dataBillSettingAfterDelete = function(event) {
//			alert('删除之后！')
		}



		
		
		/**
		name:bizData#onIndexChanged
		description: <b>[回调型事件]</b>行记录变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"rowID" : 行Id,
			"rowIndex" : 行索引
		}
		</xmp>	
		*/
		Model.dataBillSettingIndexChanged = function(event) {
			
		}
		
		/**
		name:bizData#onDataChanged
		description: <b>[回调型事件]</b>数据发生变化（包括新增、刷新、删除、修改引起的变化），感知从data的变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"changedSource" ：触发变化的组件的js对象，当从data触发时返回从data对象,
			"selfChanged" : 是否自身变化，false：从data触发的变化,
			"type" : 触发变化的类型，包括：new、delete、refresh、valueChanged、clear，其他参数根据触发类型不同给出不同参数，参考onAfterNew等事件参数
		}
		</xmp>	
		*/
		Model.dataBillSettingDataChanged = function(event) {
			
		}
		
		/**
		name:bizData#onValueChanged
		description: <b>[回调型事件]</b>数据变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"column" : 关系,
			"rowIndex" : 行索引,
			"value" : 新值,
			"originalValue" : 旧值
		}
		</xmp>	
		*/
		//输入值变化，监视input的输入，ng-change
		Model.dataBillSettingValueChanged = function(event) {

		}
		

		
		
		
		//定义页面级别的变量

		/**
		name:bizData#onBeforeNew
		description: <b>[回调型事件]</b>业务数据新增前
		@param {object} event 它的结构如下:<br/>{"source":组件的js对象,"cancel":可修改，设置为true后中断当前new动作}
		 */
		Model.dataBillSettingBeforeNew = function(event) {

		};
		/**
		 * name:bizData#onAfterNew description: <b>[回调型事件]</b>业务数据新增后
		 * 
		 * @param event
		 *            它的结构如下:<br/>{"source":组件的js对象,"id":新增的行Id}
		 */
		Model.dataBillSettingAfterNew = function(event){
			
		}

		Model.dataBillSettingAfterSave = function(event) {
			//保存成功
			$uibModalInstance.close(0);
		};

	    //接受参数
		Model.params = $rootScope.$stateParams;  

		
		var options = {};
		options.container = Model;
		options.concept = 'BillSetting';
		options.name = 'dataBillSetting';
		options.url = $rootScope.path;
		options.httpUrl = $rootScope.getServiceName();
		options.creater = '/backcenter/billSetting/list/create';
		options.reader = '/backcenter/billSetting/list/query';
		options.writer = '/backcenter/billSetting/list/save';
		options.deleter = '/backcenter/billSetting/list/delete';
		options.idColumnDefine = "fID";
		options.idColumnName = "fID";
		options.defCols = {fID:{name:"fID",type:"String",label:""},appId:{name:"appId",type:"String",label:""},appName:{name:"appName",type:"String",label:""},billType:{name:"billType",type:"String",label:""},billTypeName:{name:"billTypeName",type:"String",label:""},preChar:{name:"preChar",type:"String",label:""},codeType:{name:"codeType",type:"String",label:""},codeCount:{name:"codeCount",type:"Integer",label:""},dealType:{name:"dealType",type:"Integer",label:""},autoCode:{name:"autoCode",type:"String",label:""},direction:{name:"direction",type:"Integer",label:""},costingCode:{name:"costingCode",type:"String",label:""},revOpay:{name:"revOpay",type:"String",label:""},revOpayLabel:{name:"revOpayLabel",type:"String",label:""},origin:{name:"origin",type:"String",label:""},flowType:{name:"flowType",type:"Integer",label:""},originName:{name:"originName",type:"String",label:""},fMasterID:{name:"fMasterID",type:"String",label:""},codeTypeLabel:{name:"codeTypeLabel",type:"String",label:""},autoCodeLabel:{name:"autoCodeLabel",type:"String",label:""},directionLabel:{name:"directionLabel",type:"String",label:""},costingCodeLabel:{name:"costingCodeLabel",type:"String",label:""},flowTypeLabel:{name:"flowTypeLabel",type:"String",label:""},billLog:{name:"billLog",type:"String",label:""},windowProcess:{name:"windowProcess",type:"String",label:""},windowActivity:{name:"windowActivity",type:"String",label:""},version:{name:"version",type:"Integer",label:""}};
		options.isTree = false;
		options.parentRelation = 'sParent';
		options.nodeKindRelation = 'sNodeKind';
		options.nodeLevelRelation = 'sLevel';
		options.pathRelation = 'sFID';
		options.directDeleteMode = true;
		options.limit = 10;
		
		options.onIndexChanging = null;
		options.onIndexChanged = Model.dataBillSettingIndexChanged;
		options.onBeforeNew = Model.dataBillSettingBeforeNew;
		options.onAfterNew = Model.dataBillSettingAfterNew;
		options.onBeforeDelete = Model.dataBillSettingBeforeDelete;
		options.onAfterDelete = Model.dataBillSettingAfterDelete;
		options.onValueChanged = Model.dataBillSettingValueChanged;
		options.onDataChanged = Model.dataBillSettingDataChanged;
		options.onAfterRefresh = Model.dataBillSettingAfterRefresh;
		options.onAfterSave = Model.dataBillSettingAfterSave;
		
		$scope.dataBillSetting = new BizData(options);

		//监视对象中的所有变动
		$scope.dataBillSetting.deregRows = $scope.$watch('dataBillSetting.rows',$scope.dataBillSetting.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
		//////////////////////////////////////////////
		
		
		//增加过滤条件，只显示当前用户的
//		$scope.dataBillSetting.filter = "BillSetting.fMasterID='" + Model.params.id + "'";
//		$scope.dataBillSetting.fMasterID = Model.params.id;
//		$scope.dataBillSetting.refreshData();
		
		
		//////////////////////对话框使用开始//////////////////////////////////////
        //模态窗口打开之后执行的事件
        $uibModalInstance.opened.then(function(){
    		//接收调用对话框的参数
            Model.title = title;  
            Model.params = params;  
    		 
    		if(Model.params.recordState=='new'){
    			$scope.dataBillSetting.loadData('');
	   		     var options = {
				         index : 0,
				         defaultValues : [
				             {
//				            	 state:'active'
//				            	 ,status:'open'
//				            	 ,audit:'active'
//				            	 ,orderDate:systemService.getCurrentDate(false)
				            	 
				            	 fMasterID:Model.params.id
				            	 ,codeCount:0
				            	 ,direction:1
				            	 ,flowType:1
				            	 
				            	 ,appId:Model.params.appId
				            	 ,appName: Model.params.appName
				            	 
				            	 ,version:0
				            }//,
	//			             {itemNo:'a2',itemDescribe:'b2'}
				         ]
				     };    
	
				$scope.dataBillSetting.newData(options);
    		}
    		if(Model.params.recordState=='edit'){
    			$scope.dataBillSetting.id = Model.params.id;
    		    $scope.dataBillSetting.refreshData();
    		}
        });  
		
		//修改
		Model.edit = function(){
			$scope.dataBillSetting.editData();
		}
		
	    Model.ok = function () {  
	    	$scope.dataBillSetting.saveData();
	    };  
	    
	    Model.cancel = function () {  
	    	/*
			//返回至列表页面
			var to = '/backcenter/subsysBill/list';
			var params = {
					"id":$scope.dataBillSetting.data.rows[$scope.dataBillSetting.currentIndex].fMasterID.value
					,"recordState":"none"
					};
			var options = {};
			$state.go(to,params,options);
			*/
	        $uibModalInstance.dismiss('cancel');  
			
	    };    
	    

	    //编码类型
	    $scope.dataCodeType = [
            {value:'DT',label:'日期型'}
            ,{value:'NB',label:'流水号'}
            ];
	    //编码长度
	    $scope.dataCodeCount = [
            10
            ,15
            ];
	    //编码类型
	    $scope.dataCostingCode = [
            {value:'S',label:'S.成本来源'}
            ,{value:'V',label:'V.成本赋值'}
            ,{value:'y',label:'y.成本调整'}
            ,{value:'N',label:'N.无影响'}
            ];
	    //收入/支出
	    $scope.dataRevOpay = [
            {value:'I',label:'I.收入'}
            ,{value:'O',label:'O.支出'}
            ,{value:'-',label:'-.调拨'}
            ,{value:'9',label:'9.其他'}
            ];
	    //蓝字/红字
	    $scope.dataDirection = [
            {value:1,label:'1.蓝字'}
            ,{value:-1,label:'-1.红字'}
            ];
	    //交易类别
	    $scope.dataDealType = [
            {value:0,label:'0.--选择交易类别 --'}
            ,{value:1,label:'1.入库'}
            ,{value:2,label:'2.销货'}
            ,{value:3,label:'3.领用'}
            ,{value:4,label:'4.调拨'}
            ,{value:5,label:'5.调整'}
            ];

	    //审签方式
	    $scope.dataFlowType = [
            {value:0,label:'0:不送审自动审核'}
            ,{value:1,label:'1:非工作流审签'}
            ,{value:2,label:'2:自由工作流审签'}
            ,{value:3,label:'3:工作流审签'}
            ];

	
		return Model;
		
	}
    
    
//})

